package com.example.admin.controller;

import com.example.admin.Dto.LoginDto;
import com.example.admin.Vo.UserVo;
import com.example.admin.base.ResponseResult;

import com.example.admin.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/security")
public class Logincon {
    @Autowired
    Userservice userservice;
    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;
    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginDto loginDto){
        try {
            String encode = bCryptPasswordEncoder.encode("123");
            System.out.println(encode);
            System.out.println(loginDto.getUsername()+"///////"+loginDto.getPassword());
           UserVo uservo = userservice.login(loginDto);
            return ResponseResult.success(uservo);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }

    }
}
